package cn.kgc.ubagnet.service.buyer;

import cn.kgc.ubagnet.mapper.BuyerMapper;
import cn.kgc.ubagnet.pojo.Buyer;
import cn.kgc.ubagnet.pojo.BuyerExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shkstart
 * @create 2020-08-04 11:33
 */
@Service
public class BuyerServiceImpl implements BuyerService {


    @Resource
    BuyerMapper buyerMapper;

    @Override
    public Integer addBuyer(Buyer buyer) {
        return   buyerMapper.insert(buyer);
    }

    @Override
    public Buyer seleByPhone(String phone) {
        BuyerExample example=new BuyerExample();
        BuyerExample.Criteria criteria = example.createCriteria();
        if(!"".equals(phone)){
            criteria.andPhoneEqualTo(phone);
            List<Buyer> buyers = buyerMapper.selectByExample(example);
            if(buyers.size()>0){
                return buyers.get(0);
            }else{
                return null;
            }
        }else{
            return null;
        }
    }

    @Override
    public Integer upBuyer(Buyer buyer) {
        return buyerMapper.updateByPrimaryKeySelective(buyer);
    }


}
